for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
'use strict';
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
// Boook schema definition
const BookSchema = new Schema({
title: {
type: String,
required: true
},
author: {
year: {
type: Number,
pages: {
createdAt: {
type: Date,
default: Date.now
}
}, {
versionKey: false
});
// Sets the createdAt parameter equal to the current time
BookSchema.pre('save', next => {
const now = new Date();
if (!this.createdAt) {
this.createdAt = now;
next();
// Exports the BookSchema for use elsewhere
module.exports = mongoose.model('book', BookSchema);